$safedatasry) { if (get_magic_quotes_gpc ()) { $safedatasry = stripslashes ($safedatasry); } $firste[$safedatafor] = addslashes ($safedatasry); } return $firste; } if (get_magic_quotes_gpc ()) { $safedatasry = stripslashes ($safedatasry); } $firste = addslashes (stripslashes ($firste)); return $firste; } if ($second == 'display') { if (is_array ($firste)) { foreach ($firste as $safedatafor => $safedatasry) { $firste[$safedatafor] = htmlspecialchars (stripslashes ($safedatasry), ENT_QUOTES); } return $firste; } $firste = htmlspecialchars (stripslashes ($firste), ENT_QUOTES); } return $firste; } function price ($price) { $price = preg_replace('/[^0-9.]/', '', $price); $price = explode ('.', $price); return $price[0]; } function check_pass ($checkpassfirste, $checkpasssecond) { $checkpassry = true; if ($checkpassfirste !== $checkpasssecond) { $checkpassry = false; } if (!((!(strlen ($checkpassfirste) < 6) AND !(20 < strlen ($checkpassfirste))))) { $checkpassry = false; } if (!((!ereg ('[[:punct:]]', $checkpassfirste) AND !ereg ('[[:space:]]', $checkpassfirste)))) { $checkpassry = false; } return $checkpassry; } function check_user ($checkuserone) { $checkpassry = true; if (!((!(strlen ($checkuserone) < 6) AND !(20 < strlen ($checkuserone))))) { $checkpassry = false; } if (!((!ereg ('[[:punct:]]', $checkuserone) AND !ereg ('[[:space:]]', $checkuserone)))) { $checkpassry = false; } return $checkpassry; } function check_email ($checkemailone) { $checkemailtou = '/^([_a-z0-9-]+)(\\.[_a-z0-9-]+)*@([a-z0-9-]+)(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})$/i'; $checkpassry = false; if (preg_match($checkemailtou, $checkemailone)) { $checkpassry = true; } return $checkpassry; } function summary ($summaryone, $summarytou) { if ($summarytou < substr_count ($summaryone, ' ')) { $summaryone = explode (' ', $summaryone); $summaryone = array_slice ($summaryone, 0, $summarytou); $summaryone = implode (' ', $summaryone) . ' ...'; } return $summaryone; } function new_dim ($newdimone, $newdimtou, $newdimsry, $newdimfor) { if ($newdimsry < $newdimone) { $newdimfive = $newdimsry / $newdimone; $newdimone = $newdimsry; $newdimtou = round ($newdimtou * $newdimfive); } if ($newdimfor < $newdimtou) { $newdimfive = $newdimfor / $newdimtou; $newdimtou = $newdimfor; $newdimone = round ($newdimone * $newdimfive); } return array ('x' => $newdimone, 'y' => $newdimtou); } function resize ($resizeone, $resizetou, $newdimone, $newdimtou, $resizestry, $resizefor, $resizefive) { if ($resizefive == 2) { $resizeone = imagecreatefromjpeg ($resizeone); $resizesex = imagecreatetruecolor ($resizestry, $resizefor); imagecopyresampled ($resizesex, $resizeone, 0, 0, 0, 0, $resizestry, $resizefor, $newdimone, $newdimtou); touch ($resizetou); imagejpeg ($resizesex, $resizetou); imagedestroy ($resizesex); return null; } if ($resizefive == 3) { $resizeone = imagecreatefrompng ($resizeone); $resizesex = imagecreatetruecolor ($resizestry, $resizefor); imagecopyresampled ($resizesex, $resizeone, 0, 0, 0, 0, $resizestry, $resizefor, $newdimone, $newdimtou); touch ($resizetou); imagepng ($resizesex, $resizetou); imagedestroy ($resizesex); } } function dropdown ($dropdownone, $dropdowntou) { foreach ($dropdownone as $safedatasry) { $safedatasry = str_replace ('', '', $safedatasry); echo ''; } } function dropdown_province ($dropdownone, $dropdowntou) { foreach ($dropdownone as $safedatasry) { $safedatasry = str_replace ('', '', $safedatasry); echo ''; } else if((trim ($safedatasry) == 'North Island') || (trim ($safedatasry) == 'South Island')) { echo '     ' . trim ($safedatasry) . ''; } else { echo '         ' . trim ($safedatasry) . ''; } } } function dropdown_provience ($dropdownone, $dropdowntou) { foreach ($dropdownone as $safedatasry) { $safedatasry = str_replace ('', '', $safedatasry); echo ''; } else { echo '>    ' . ($safedatasry) . ''; } } } function page_links ($firste, $pagelinksone, $pagelinkstou) { foreach ($firste as $safedatafor => $safedatasry) { if ($safedatafor != 'page') { $checkpassfirste .= '&' . $safedatafor . '=' . $safedatasry; continue; } } if (1 < $firste[page]) { echo 'Prev  '; } if (1 < $pagelinksone) { if (1 <= $firste[page] - 5) { $pagelinkssri = $firste[page] - 5; } else { $pagelinkssri = 1; } if ($pagelinkssri + 9 <= $pagelinksone) { $pagelinksfor = $pagelinkssri + 9; } else { $pagelinksfor = $pagelinksone; if (1 <= $pagelinksfor - 9) { $pagelinkssri = $pagelinksfor - 9; } else { $pagelinkssri = 1; } } for ($pagelinksfive = $pagelinkssri; $pagelinksfive <= $pagelinksfor; ++$pagelinksfive) { echo '' . $pagelinksfive . ' '); } } if ($firste[page] < $pagelinksone) { echo ' Next'; } } function filter_string ($summaryone) { $filterstringone = array ('content-type', 'mime-version', 'multipart/mixed', 'content-transfer-encoding', 'bcc:', 'cc:', 'to:'); foreach ($filterstringone as $filterstringtou) { if (substr_count (strtolower ($summaryone), $filterstringtou)) { exit ('Suspected email injection attempt from ' . $_SERVER[REMOTE_ADDR] . ' - mail not being sent.'); } } } function filter_newline ($summaryone) { if (preg_match ('/(%0a|%0d|\\n+|\\r+)/i', strtolower ($summaryone)) != 0) { exit ('Suspected email injection attempt from ' . $_SERVER[REMOTE_ADDR] . ' - mail not being sent.'); } } function get_field_info($loc_id,$cat_type,$field_name,$link) { $result = mysql_query ('SELECT * FROM locations WHERE id=\'' .$loc_id . '\' LIMIT 1', $link); $row = mysql_fetch_array ($result); switch($cat_type) { case 'listing': $result1 = mysql_query (' SELECT * FROM field_setting WHERE file_name=\''.trim($row['file_listing_fields']).'\' AND category_type="listing" AND field_name = \'' .$field_name . '\'', $link); $data = mysql_fetch_array ($result1); return $data; break; case 'user': $result1 = mysql_query (' SELECT * FROM field_setting WHERE file_name=\''.trim($row['file_user_fields']).'\' AND category_type="user" AND field_name = \'' .$field_name . '\'', $link); $data = mysql_fetch_array ($result1); return $data; break; case 'location': $result1 = mysql_query (' SELECT * FROM field_setting WHERE file_name=\''.trim($row['field_file']).'\' AND category_type="location" AND field_name = \'' .$field_name . '\'', $link); $data = mysql_fetch_array ($result1); return $data; break; } } ////To get province according to area range function getProvinceUnderLocation($name = 'NZ',$province_data) { $provinces = ''; switch($name) { case'NZ': foreach (explode("\n", $province_data) as $safedatasry) { if(trim($safedatasry) != 'NZ') { if((trim($safedatasry) != 'North Island') && (trim($safedatasry) != 'South Island')) { $provinces .= '"'.trim($safedatasry).'",'; } } } break; case'North Island': $i = 0; foreach (explode("\n", $province_data) as $safedatasry) { if(trim($safedatasry) == 'North Island') { $i = 1; } if(trim($safedatasry) == 'South Island') { $i = 0; } if($i == 1) { if(trim($safedatasry) != 'North Island') { $provinces .= '"'.trim($safedatasry).'",'; } } } break; case'South Island': $i = 0; foreach (explode("\n", $province_data) as $safedatasry) { if(trim($safedatasry) == 'South Island') { $i = 1; } if($i == 1) { if(trim($safedatasry) != 'South Island') { $provinces .= '"'.trim($safedatasry).'",'; } } if(trim($safedatasry) == 'North Island') { $i = 0; } } break; default: break; } return substr($provinces,0,-1); } /////Function to get images function get_list_images($list_id, $dblist, $dbimgs, $link) { $tem = array(); $result_ajax = mysql_query("SELECT * FROM $dblist WHERE id='".$list_id."' LIMIT 1",$link); $row_ajax = mysql_fetch_array($result_ajax); if($row_ajax['images']) { $images = array(); $result_ajax_img = mysql_query("SELECT fname FROM $dbimgs WHERE listid='".$list_id."' ORDER BY id ASC"); while($images_ajax = mysql_fetch_array($result_ajax_img)) { $check_value = strpos($images_ajax['fname'],'_'); if($check_value) { $first_pos = explode('_',$images_ajax['fname']); $second_pos = explode('.',$first_pos[1]); $tem[$second_pos[0]] = $images_ajax['fname']; } else { array_push($images, $images_ajax['fname']); } } if(count($tem) > 0) { ksort($tem); foreach($tem as $values) { array_push($images, $values); } } } $total = count($images); $selected = array_slice($images, $first, $length); return $selected; } function to_create_gallery($images_array) { global $main_site_path; $list_str = ''; } function redirect($page='',$query_str='') { $page_url = ''; if($page != ''){ $page_url = CURRENT_SITE_PATH.'/'.$page.'/'; } if($query_str != '') { $page_url .='&'.$query_str; } if($page_url != '') { header('Location:'.$page_url); } } function get_field_value($table='',$id=0,$field_name='') { switch($table) { case"locations": $result = mysql_query ('SELECT '.$field_name.' FROM locations WHERE id=\'' .$id . '\' LIMIT 1'); $row = @mysql_fetch_array ($result); return trim($row[$field_name]); break; case"temp_images": $result = mysql_query ('SELECT '.$field_name.' FROM temp_images WHERE image_path =\'' .trim($id) . '\' LIMIT 1'); $row = @mysql_fetch_array ($result); return trim($row[$field_name]); break; case"users": $result = mysql_query ('SELECT '.$field_name.' FROM users WHERE id=\'' .$id . '\' LIMIT 1'); $row = @mysql_fetch_array ($result); return trim($row[$field_name]); break; case"listings": $result = mysql_query ('SELECT '.$field_name.' FROM listings WHERE id=\'' .$id . '\' LIMIT 1'); $row = @mysql_fetch_array ($result); return trim($row[$field_name]); break; default: return false; break; } } function get_total_listings($where='',$from='',$link='') { $total_records = 0; if(($where != '') && ($from != '')) { $result = mysql_query ('SELECT COUNT(*) as total FROM '.$from.' WHERE '.$where.' ', $link); $row = mysql_fetch_array ($result); $total_records = $row['total']; } return $total_records; } function dateFormat($date='',$seperater='/',$check='front') { $return_date = ''; $make_changes = 0; if($date != '') { if(strpos($date,$seperater) > 0) { ///Do nothing } else { $make_changes = 1; } $date_array = explode($seperater,$date); if((count($date_array) > 0) && ($make_changes == 0)){ if($check == 'front') { $return_date = $date_array[2].'-'.$date_array[1].'-'.$date_array[0]; } else { $return_date = $date_array[2].'/'.$date_array[1].'/'.$date_array[0]; } } else { $return_date = $date; } } return $return_date; } function get_last_insert_listID($userid=0,$link='') { global $dblist,$final_id; $last_insert_id_value = 0; $result_max = mysql_query ('SELECT MAX(id) as last_list_id FROM ' . $dblist . ' WHERE userid=\'' . $userid . '\' '); $fetched_records = mysql_fetch_array ($result_max); $last_insert_id_value = $fetched_records['last_list_id']; if (!$last_insert_id_value) { $result_max = mysql_query ('SELECT MAX(id) as last_list_id FROM ' . $dblist . '', $link); $row_max = mysql_fetch_array ($result_max); $last_insert_id_value = $row_max['last_list_id']; } $auto_increase = 1; $filtered_last_id = ''; if($last_insert_id_value) { $user_id_length = strlen($userid); $count_last_id_length = strlen($last_insert_id_value); if($count_last_id_length > $user_id_length) { $temp_id = substr($last_insert_id_value,$user_id_length)+$auto_increase; $filtered_last_id = $userid.$temp_id; } else { $filtered_last_id = $userid.$auto_increase; } } else { $filtered_last_id = $userid.$auto_increase; } check_id_exist($filtered_last_id); return $final_id; } function check_id_exist($id=0) { global $dblist,$final_id; $result_list_id = mysql_query ('SELECT id FROM ' . $dblist . ' WHERE id=\'' . $id . '\' '); $fetched_id = mysql_fetch_array ($result_list_id); $list_id = $fetched_id['id']; $final_id = $id; if ($list_id > 0) { $final_id = $list_id+1; check_id_exist($final_id); } } function xml2array($contents, $get_attributes=1, $priority = 'tag') { if(!$contents) return array(); if(!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if(!$xml_values) return;//Hmm... //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference //Go through the tags. $repeated_tag_index = array();//Multiple tags with same name will be turned into an array foreach($xml_values as $data) { unset($attributes,$value);//Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data);//We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if(isset($value)) { if($priority == 'tag') $result = $value; else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode } //Set the attributes too. if(isset($attributes) and $get_attributes) { foreach($attributes as $attr => $val) { if($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } //See tag status and do the needed. if($type == "open") {//The starting of the tag '' $parent[$level-1] = &$current; if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if($attributes_data) $current[$tag. '_attr'] = $attributes_data; $repeated_tag_index[$tag.'_'.$level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if(isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; $repeated_tag_index[$tag.'_'.$level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag.'_'.$level] = 2; if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } } $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1; $current = &$current[$tag][$last_item_index]; } } elseif($type == "complete") { //Tags that ends in 1 line '' //See if the key is already taken. if(!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data; } else { //If taken, put all things inside a list(array) if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array... // ...push the new element into that array. $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result; if($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag.'_'.$level]++; } else { //If it is not an array... $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value $repeated_tag_index[$tag.'_'.$level] = 1; if($priority == 'tag' and $get_attributes) { if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag.'_attr']; unset($current[$tag.'_attr']); } if($attributes_data) { $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken } } } elseif($type == 'close') { //End of tag '' $current = &$parent[$level-1]; } } return($xml_array); } function get_MAX_value($table='',$id=0,$field_name='',$link='') { switch($table) { case"vosa": $result = mysql_query ('SELECT MAX('.$field_name.') FROM vosa WHERE user_id=\'' .$id . '\' LIMIT 1', $link); $row = mysql_fetch_array ($result); return trim($row[$field_name]); break; default: return false; break; } } function get_post_permissions($post='',$type='') { $str = ''; if(isset($post['edit_'.$type])) { $str = '1,'; } else { $str = '0,'; } if(isset($post['view_'.$type])) { $str .= '1,'; } else { $str .= '0,'; } return $str .= $type.';'; } function check_childs($parent_id='') { global $pages_table; if($parent_id != '') { $pages_result_display = mysql_query("SELECT * FROM ".$pages_table." WHERE parent=".$parent_id.""); $affected_records = mysql_affected_rows(); if($affected_records > 0) { return true; } else { return false; } } } function check_selected_permission($allpermissions='',$page='',$type='',$userStatus='',$user_type='') { $permission_arr = explode(';',$allpermissions); $return_val = 0; for($i=0; $i < count($permission_arr); $i++) { $per_page_permission = explode(',',$permission_arr[$i]); if(($per_page_permission[2] == $page) && ($type == 'edit')) { $return_val = $per_page_permission[0]; } else if(($per_page_permission[2] == $page) && ($type == 'view')) { $return_val = $per_page_permission[1]; } } if(($userStatus == 1) || ($user_type == 3)) { $return_val = 1; } return $return_val; } function get_allow_pages($allpermissions='',$permission_type='',$userStatus='',$user_type='') { global $pages_table; $pages_array = array(); $permission_arr = explode(';',$allpermissions); for($i=0; $i < count($permission_arr); $i++) { $per_page_permission = explode(',',$permission_arr[$i]); if(($permission_type == 'edit') && ($per_page_permission[0] == 1)) { $pages_array[] = trim($per_page_permission[2]); } else if(($permission_type == 'view') && ($per_page_permission[1] == 1)) { $pages_array[] = trim($per_page_permission[2]); } } if(($userStatus == 1) || ($user_type == 3)) { $tab_result = mysql_query("SELECT * FROM ".$pages_table." "); while($row = mysql_fetch_array($tab_result)) { $pages_array[] = trim($row['tab_default_id']); } } return $pages_array; } function get_top_level_permission($user_type='') { global $pages_table; $tab_array = array(); if($user_type != '') { $tab_result = mysql_query("SELECT * FROM ".$pages_table." WHERE top_permissions like '%".$user_type."%'"); while($row = mysql_fetch_array($tab_result)) { $tab_array[] = trim($row['tab_default_id']); } } return $tab_array; } function get_permission($viewPer=array(),$editPer=array(),$tab='') { $return_permission = ''; if(in_array($tab,$editPer)) { $return_permission = 'edit'; } else if(in_array($tab,$viewPer)) { $return_permission = 'view'; } return $return_permission; } function get_user_types($type=''){ global $user_type_table; $where = ''; if($type != '') { if($type != 3) { $where = ' WHERE user_type_id='.$type; } $return_type = array(); $tab_result = mysql_query("SELECT * FROM ".$user_type_table.$where." ORDER BY user_type_id"); $i = 1; while($row = mysql_fetch_array($tab_result)) { $return_type[trim($row['user_type_id'])] = trim($row['user_type']); $i++; } } return $return_type; } function get_contact_records($contact_id='') { global $vehicle_quote_table,$newsletters_table; $other_content_array = array(); $sql_quote = "SELECT create_date FROM ".$vehicle_quote_table." WHERE contact_id='".$contact_id."' ORDER BY create_date ASC"; $result_quote = mysql_query($sql_quote) or die(mysql_error()); $isrecords_quote = mysql_affected_rows(); if($isrecords_quote > 0){ $j=0; while($row_quote = mysql_fetch_array($result_quote)){ $other_content_array[$j] = array($row_quote['create_date'],'Vehicle Quote'); $j++; }///End inner while here } $sql_newsletter = "SELECT create_date FROM ".$newsletters_table." WHERE contact_id='".$contact_id."' ORDER BY create_date ASC"; $result_newsletter = mysql_query($sql_newsletter) or die(mysql_error()); $isrecords_newsletter = mysql_affected_rows(); if($isrecords_newsletter > 0){ $k=0; while($row_newsletter = mysql_fetch_array($result_newsletter)){ $other_content_array[$k] = array($row_newsletter['create_date'],'Newsletter - Emailed'); $k++; }///End inner while here } return $other_content_array; } function get_default_cost($location_id='',$user_id='',$type='') { global $default_cost_table; $return_array = array(); if($location_id != '') { $cost_result = mysql_query("SELECT location_cost_id, cost, retail, fee_type FROM ".$default_cost_table." WHERE location_id=".$location_id." AND user_id=".$user_id." AND cost_type='".$type."' ORDER BY fee_type "); $i = 0; while($row = mysql_fetch_array($cost_result)) { $return_array[$i] = array('location_cost_id'=>$row['location_cost_id'],'cost'=>$row['cost'],'retail'=>$row['retail'],'fee_type'=>$row['fee_type']); $i++; } } return $return_array; } function get_product_service_list($user_id='') { global $product_service_list_table; $return_array = array(); if($user_id != '') { $list_result = mysql_query("SELECT product_service_list_id, product_service_list_name FROM ".$product_service_list_table." WHERE user_id=".$user_id." OR user_type='3' ORDER BY product_service_list_name "); $i = 0; while($row = mysql_fetch_array($list_result)) { $return_array[$i] = array('product_service_list_id'=>$row['product_service_list_id'],'product_service_list_name'=>$row['product_service_list_name']); $i++; } } return $return_array; } function get_product_service($service_id='') { global $product_service_list_table; $return_array = array(); if($service_id != '') { $list_result = mysql_query("SELECT product_service_list_id, product_service_list_name FROM ".$product_service_list_table." WHERE product_service_list_id =".$service_id.""); $return_array = mysql_fetch_assoc($list_result); } return $return_array; } function get_contacts_list($id='',$id_val='',$user_type='',$days='') { global $contacts_table,$address_book_table; $where = " WHERE c.".$id_val." ='".$id."' AND `create_date`>0"; if($days > 0) { $where .= ' AND `create_date` >= date_sub(NOW(),interval '.$days.' day) AND `create_date`>0'; } if($user_type == 3) { if($days > 0) { $where = ' WHERE `create_date` >= date_sub(NOW(),interval '.$days.' day) AND `create_date`>0'; } else { $where = ''; } } $return_array = array(); if($id != '') { $list_result = mysql_query("SELECT c.*,a.* FROM ".$contacts_table." as c LEFT JOIN ".$address_book_table ." as a ON c.address_book_id = a.address_book_id ".$where.""); $i = 0; while($row = mysql_fetch_array($list_result)) { $return_array[$i] = array('contact_id'=>$row['contact_id'],'salutation'=>$row['salutation'],'first_name'=>$row['first_name'],'last_name'=>$row['last_name'],'middle_name'=>$row['middle_name'],'employer'=>$row['employer'],'job_title'=>$row['job_title'],'home'=>$row['home'],'work'=>$row['work'],'mobile'=>$row['mobile'],'fax'=>$row['fax'],'email'=>$row['email'],'dob'=>$row['dob'],'licence_number'=>$row['licence_number'],''=>$row['version'],''=>$row['version'],''=>$row['gender'],''=>$row['gender'],''=>$row['marital_status'],''=>$row['marital_status'],'address_book_id'=>$row['address_book_id'],'occupation'=>$row['occupation'],'physical_street_address'=>$row['physical_street_address'],'physical_subrub'=>$row['physical_subrub'],'physical_city'=>$row['physical_city'],'physical_post_code'=>$row['physical_post_code'],'create_date'=>$row['create_date']); $i++; } } return $return_array; } function get_PDF_fields($page_name) { $return_array = array(); switch($page_name) { case'salesStocklist': $return_array['width'] = array(25,45,25,20,35,20,25,25,25); $return_array['width_p'] = array(30,15,50,20,20,35,20,25,25,22); $return_array['cols'] = array('Stock','Year/Make/Model','Colour','CC','Category','Fuel','Rege','Retails','Expenses'); $return_array['cols_p'] = array('Photo','Stock','Year/Make/Model','Colour','CC','Category','Fuel','Rege','Retails','Expenses'); $return_array['bottom_width_p'] = array(30,15,50,20,20,35,20,25,25,22); $return_array['bottom_width'] = array(25,45,25,20,35,20,25,25,25); $return_array['page_number_x'] = 240; $return_array['page_number_x_p'] = 257; $return_array['date_width_p'] = array(207,50); $return_array['date_width'] = array(201,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'purchasers': $return_array['width'] = array(25,45,25,20,35,20,25,25,25); $return_array['width_p'] = array(30,15,50,20,20,35,20,25,25,22); $return_array['cols'] = array('Name','Street Address','Birthday','Age','Home','Work','Mobile','Email','Stock Obtained'); $return_array['cols_p'] = array('Photo','Name','Street Address','Birthday','Age','Home','Work','Mobile','Email','Stock Obtained'); $return_array['bottom_width_p'] = array(); $return_array['bottom_width'] = array(25,45,25,20,35,20,25,25,25); $return_array['page_number_x'] = 250; $return_array['page_number_x_p'] = 265; $return_array['date_width_p'] = array(218,50); $return_array['date_width'] = array(201,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'manager': $return_array['width'] = array(20,40,20,20,25,30,30,30,30,25); $return_array['width_p'] = array(25,20,40,15,15,20,25,30,25,25,25); $return_array['cols'] = array('Stock','Year/Make/Model','Colour','CC','Transmission','Cost','Retail','Expenses','Days On Yard','Tradein Stock#'); $return_array['cols_p'] = array('Photo','Stock','Year/Make/Model','Colour','CC','Transmission','Cost','Retail','Expenses','Days On Yard','Tradein Stock#'); $return_array['page_number_x'] = 265; $return_array['page_number_x_p'] = 257; $return_array['date_width_p'] = array(230,50); $return_array['date_width'] = array(225,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'tradein': $return_array['width'] = array(50,50,50,45,40,30); $return_array['width_p'] = array(); $return_array['cols'] = array('Date Traded','Vehicle Traded','Vendor','Vehicle purchased','Trade Price','Written Back'); $return_array['cols_p'] = array(); $return_array['page_number_x'] = 265; $return_array['page_number_x_p'] = 0; $return_array['date_width_p'] = array(); $return_array['date_width'] = array(221,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'maintenance': $return_array['width'] = array(35,45,30,30,30,30,30,30); $return_array['width_p'] = array(25,30,40,25,25,30,35,25,25); $return_array['cols'] = array('Stock','Year','Make','Model','WOF Due','Days Until Expires','Rego Due','Days Until Expires'); $return_array['cols_p'] = array('Photo','Stock','Year','Make','Model','WOF Due','Days Until Expires','Rego Due','Days Until Expires'); $return_array['page_number_x'] = 265; $return_array['page_number_x_p'] = 265; $return_array['date_width_p'] = array(216,50); $return_array['date_width'] = array(216,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'vv': $return_array['width'] = array(20,13,13,15,15,10,13,13,13,15,10,10,13); $return_array['cols'] = array('Photo','Stock No.','Date Sold','Purchaser','Vehicle','Cost','Recon','Extras','Allow','Finance','Due','Trade In','Vender'); $return_array['bottom_width'] = array(135); $return_array['bottom_cols'] = array(''); break; case'salesReport': $return_array['page_number_x'] = 215; $return_array['page_number_x_p'] = 240; $return_array['width'] = array(15,20,30,25,20,20,20,20,20,20,20,20); $return_array['width_p'] = array(25,15,20,30,20,25,20,20,20,20,20,20,20); $return_array['cols'] = array('Stock','Date Sold','Purchaser','Vehicle','Cost','Expenses','Cash','Extras','Trade','Deposits','Finance','Due'); $return_array['cols_p'] = array('Photo','Stock','Date Sold','Purchaser','Vehicle','Cost','Expenses','Cash','Extras','Trade','Deposits','Finance','Due'); $return_array['bottom_width_p'] = array(25,15,20,30,20,25,20,20,20,20,20,20,20); $return_array['bottom_width'] = array(15,20,30,25,20,20,20,20,20,20,20,20); $return_array['date_width_p'] = array(229,50); $return_array['date_width'] = array(209,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'vehicle': $return_array['width'] = array(10,25,15,15,15,15,15,15,15,15,15,15,15,15); $return_array['width_p'] = array(25,10,25,15,15,15,15,15,15,15,15,15,15,15,15); $return_array['cols'] = array('Stock','Year/Make/Model','Clean','comm','comp','Deliver','Fuel','Mach','Other','Panel','Paint','Parts','Rego','Trim','Tyres','Warr'); $return_array['cols_p'] = array('Photo','Stock','Year/Make/Model','Clean','comm','comp','Deliver','Fuel','Mach','Other','Panel','Paint','Parts','Rego','Trim','Tyres','Warr'); $return_array['page_number_x'] = 215; $return_array['page_number_x_p'] = 240; $return_array['bottom_cols'] = array(10,25,15,15,15,15,15,15,15,15,15,15,15); $return_array['bottom_cols_p'] = array(25,10,25,15,15,15,15,15,15,15,15,15,15,15); $return_array['date_width_p'] = array(229,50); $return_array['date_width'] = array(226,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; case'suppliers': $return_array['width'] = array(55,45,40,40,40,40); $return_array['width_p'] = array(25,55,30,40,40,40,40); $return_array['cols'] = array('Suppliers','Invoice Date','Stock','Year/Make/Model','Reference','Amount'); $return_array['cols_p'] = array('Photo','Suppliers','Invoice Date','Stock','Year/Make/Model','Reference','Amount'); $return_array['page_number_x'] = 265; $return_array['page_number_x_p'] = 265; $return_array['date_width_p'] = array(225,50); $return_array['date_width'] = array(220,50); $return_array['date_cols'] = array('','Generated '.date("j F Y g:i:s")); break; } return $return_array; } ////birthday format Y-m-d function display_age($birthday) { list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; } //////////Get expenses function get_tradein_expenses($list_id=0) { global $expenses_table; $exp = 0; if($list_id > 0) { $tradein_result = mysql_query("SELECT SUM(expenses) as ex FROM ".$expenses_table." WHERE id = '".$list_id."' GROUP BY id"); $expenses_row = mysql_fetch_array($tradein_result); $exp = $expenses_row['ex']; } return number_format($exp,2); } //////////End here /////////Display tradein write back page//////// function display_tradein_writeBack($list_id=0) { global $dblist,$dbimgs; if($list_id > 0) { $tradein_ids_result = mysql_query("SELECT tradein_id FROM ".$dblist." WHERE id='".$list_id."'"); $t_ids = mysql_fetch_array($tradein_ids_result); $tradein_result = mysql_query("SELECT * FROM ".$dblist." WHERE id in (".$t_ids['tradein_id'].") ORDER BY id"); while($row_trdein = mysql_fetch_array($tradein_result)) { $expenses = get_tradein_expenses($row[id]); $net_margin = ($row_trdein['sale']-$row_trdein['price'])-$expenses; $top_image_trdein = ''; if ($row_trdein[images]) { $result = mysql_query ('SELECT fname FROM ' . $dbimgs . ' WHERE listid=\'' . $row_trdein['id'] . '\' ORDER BY id ASC'); while ($images = mysql_fetch_array ($result)) { $top_image_trdein = ($top_image_trdein == '')?'cp-thumbs/' . $images[fname]:$top_image_trdein; } } if(!file_exists($top_image_trdein)) { $top_image_trdein = 'cp-styles/images/no-photo-thumb.jpg'; } echo '
Write Back Adjustment  
'.$row_trdein[model_year].' '.$row_trdein[make].' '.$row_trdein[model].'



Stock#:'.$row_trdein[stock].'
Net Margin:
After Write Back:
'; } } } function auto_logout($logout_period = '') { $selected_time_arr = explode(' ',$logout_period); $time_period = 24*60*60*1000; if(isset($selected_time_arr[1])) { $time_f = substr(trim($selected_time_arr[1]),0,3); if(strtolower($time_f) == 'min') { $time_period = trim($selected_time_arr[0])*60*1000; } else if(strtolower($time_f) == 'hou') { $time_period = trim($selected_time_arr[0])*60*60*1000; } } return $time_period; } function get_cost_price($list_id='') { global $landed_cost_table,$local_cost_table; if($list_id != '') { $cost_result = mysql_query('SELECT (SUM(cv.total_nzd+cv.total_tax)+SUM(lc.local_total_nzd+lc.local_total_tax)) as total_cost FROM '.$landed_cost_table.' as cv INNER JOIN '.$local_cost_table.' as lc ON cv.id=lc.id WHERE cv.id='.$list_id.' limit 1'); $cost_arr = mysql_fetch_array($cost_result); return $cost_arr['total_cost']; } } function finance_calculation($price=0,$period=0,$fRate=0) { if($price>0) { $price += DOCUMENT_FEE; } if(($fRate != '') && ($fRate > 0)) { $monthly_price = ($price*(($fRate/100)/12))/(1-pow((1+($fRate/100)/12),-$period)); $weekly_payment = ($monthly_price*12)/48; return number_format($weekly_payment,2); } } function full_finance_calculation($price=0,$period=0,$fRate=0) { if($price>0) { $price += DOCUMENT_FEE; } if(($fRate != '') && ($fRate > 0)) { $monthly_price = ($price*(($fRate/100)/12))/(1-pow((1+($fRate/100)/12),-$period)); return number_format($monthly_price,2); } } ///To stop spam function is_valid_email($email) { return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $email); } function contains_bad_str($str_to_test) { $return_str = false; $bad_strings = array( "content-type:" ,"mime-version:" ,"multipart/mixed" ,"Content-Transfer-Encoding:" ,"bcc:" ,"cc:" ,"to:" ); foreach($bad_strings as $bad_string) { // preg_quote escapes special regex characters, 'i' flag makes it case-insensitive if(preg_match('/' . preg_quote($bad_string, '/') . '/i', strtolower($str_to_test))) { $return_str = true; } } return $return_str; } function contains_newlines($str_to_test) { $return_str = false; if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) { $return_str = true; } return $return_str; } ///////Save entries in DB regarding to form submission function save_form_history($form_name='',$site_address='',$referrer_page='') { $ip_address = $_SERVER['REMOTE_ADDR']; $sent_time = date('Y-m-d h:i:s'); mysql_query("DELETE FROM form_history WHERE sent_time < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND form_name='".$form_name."' AND client_site_address='".$site_address."'"); mysql_query("INSERT INTO form_history SET ip_address='".$ip_address."', sent_time='".$sent_time."', referrer_page='".$referrer_page."', form_name='".$form_name."', client_site_address='".$site_address."'"); } ////Get weekly payment function GetMonthlyPayment($a, $p, $sfee, $monthlyFee, $trm) { $unroundedMonthlyPayment = GetMonthlyPaymentUnrounded($a, $p, $sfee, $monthlyFee, $trm); return (round($unroundedMonthlyPayment * 100) / 100); } function GetWeeklyPayment($a, $p, $sfee, $monthlyFee, $trm) { $unroundedMonthlyPayment = GetMonthlyPaymentUnrounded($a, $p, $sfee, $monthlyFee, $trm); $wp = abs(($unroundedMonthlyPayment * 12) / 52); $round_val = (round($wp * 100) / 100); return $round_val; } function GetMonthlyPaymentUnrounded($a, $p, $sfee, $monthlyFee, $trm) { $pa = abs($a) + abs($sfee); $payment = getPayment($pa, $trm, $p); $payment = $payment + abs($monthlyFee); return $payment; } function getPayment($a, $n, $p) { $acc = 0; $base = 1 + $p / 1200; for ($i = 1; $i <= $n; $i++) { $acc += pow($base, -$i); } return $a / $acc; } ?>